﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using System.Text.RegularExpressions;


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

       
        private void button1_Click(object sender, EventArgs e)
        {
            Hardwares _hardware = new Hardwares();
            HardwareProfile _profile;

            _profile = new HardwareProfile();
            _profile.Name = "ET-EASY168 STAMP";
            _profile.Fcpu = "16000000L";
            _profile.Mcu = "atmega168";
            _profile.UploadMaximum = "14336";
            _profile.UploadPotocal = "stk500";
            _profile.UploadSpeed = "19200";
            _hardware.Profile.Add(_profile);


            _profile = new HardwareProfile();
            _profile.Name = "ET-EASY168 BASE";
            _profile.Fcpu = "16000000L";
            _profile.Mcu = "atmega168";
            _profile.UploadMaximum = "14336";
            _profile.UploadPotocal = "stk500";
            _profile.UploadSpeed = "19200";
            _hardware.Profile.Add(_profile);

            XmlSerializable.WriteFile(_hardware, @"c:\Board.cfg");
        }    

        private void button2_Click(object sender, EventArgs e)
        {
            
        }

        private void button3_Click(object sender, EventArgs e)
        {
            serialPort.Open();
            serialPort.DtrEnable = true;
            System.Threading.Thread.Sleep(1000);
            serialPort.DtrEnable = false;
            serialPort.Close();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            // firstStatement
            //Regex r = new Regex("\\s+|(/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/)|(//.*?$)|(#(?:\\\\\\n|.)*)" );

            // prototypes
            Regex r = new Regex("^[\\w\\[\\]\\*]+\\s+[\\[\\]\\*\\w\\s]+\\([,\\[\\]\\*\\w\\s]*\\)(?=\\s*\\{)", RegexOptions.Multiline);

            // Var
            //Regex r = new Regex("^[\\w\\[\\]\\*]+\\s+[\\[\\]\\*\\w\\s]+\\([,\\[\\]\\*\\w\\s]*\\)(?=\\s*\\;)", RegexOptions.Multiline);
            

            //Regex r = new Regex("('.')" + "|" + "(\"(?:[^\"\\\\]|\\\\.)*\")" + "|" + "(/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/)" + "|" +"(//.*?$)" + "|" +"(^\\s*#.*?$)");

            // Include
            //Regex r = new Regex("^\\s*#include\\s+[<\"](\\S+)[\">]");
            
            Match m = r.Match(richTextBox1.Text);
            
            while (m != null && m.Success)
            {
                Console.Out.WriteLine(m.Groups[0].Value);
                //string a = m.Groups[1].Value;
                //string b = m.Groups[2].Value;

                m = m.NextMatch();
            }
        }
    }
}
